﻿#include "stdafx.h"
#include "state.h"


namespace $RootNamespace$
{

	void $Context$::Test()
	{
		// Setup pContext in a $RootNamespace$ 
		$Context$ *pContext = new $Context$(new $ConcreteStateA$());
	
		// Client requests, that changes $RootNamespace$ 
		pContext->Request();
		pContext->Request();
		pContext->Request();
	
	}

	$Context$::$Context$($IState$ *p$IState$)
	{
		m_pCurrentState = NULL;
		this->setCurrentState(p$IState$);
	}

	$IState$ *$Context$::getCurrentState()
	{
		return m_pCurrentState;
	}

	void $Context$::setCurrentState($IState$ *value)
	{
		$IState$* pOldState = m_pCurrentState;
		m_pCurrentState = value;
		if(pOldState != NULL)
			delete pOldState;
	}

	void $Context$::Request()
	{
		std::cout << "Handling Request in " + m_pCurrentState->getThisStateName() << std::endl;
		m_pCurrentState->$Handle$(this);
	}

	void $ConcreteStateA$::$Handle$($Context$ *pContext)
	{
		pContext->setCurrentState(new $ConcreteStateB$());
	}

	std::string $ConcreteStateA$::getThisStateName()
	{
		return "$ConcreteStateA$";
	}

	void $ConcreteStateB$::$Handle$($Context$ *pContext)
	{
		pContext->setCurrentState(new $ConcreteStateC$());
	}

	std::string $ConcreteStateB$::getThisStateName()
	{
		return "$ConcreteStateB$" ;
	}

	void $ConcreteStateC$::$Handle$($Context$ *pContext)
	{
		pContext->setCurrentState(new $ConcreteStateA$());
	}

	std::string $ConcreteStateC$::getThisStateName()
	{
		return "$ConcreteStateC$" ;
	}
}